#!/usr/bin/env python
# -*- coding: utf8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest
from aliyunsdkecs.request.v20140526 import StopInstanceRequest
import json
# 创建AcsClient实例
client = AcsClient(
   "LTAIjVNUVcs0a4aU", 
   "ZjgnRPYKzr2fAHOOrroRdG4IZex7al",
   "cn-beijing"
);
# 创建request，并设置参数
request = DescribeInstancesRequest.DescribeInstancesRequest()
request.set_PageSize(10)
# 发起API请求并显示返回值
response = client.do_action_with_exception(request)
print(response)
json = json.loads(response)

for instance in json['Instances']['Instance']:
    print("ZoneId", instance['ZoneId'])
    print("StartTime", instance['StartTime'])
    print("InstanceName", instance['InstanceName'])
    print("OSType", instance['OSType'])
    print("OSName", instance['OSName'])
    
    for interface in instance['NetworkInterfaces']['NetworkInterface']:
        print("PrimaryIpAddress", interface['PrimaryIpAddress'])
    
    for ipaddress in instance['PublicIpAddress']['IpAddress']:
        print("IpAddress", ipaddress)
    
    print('-----------------------------')
